#include "Score.h"
#include <graphics.h>
#include <tchar.h>
#include <Windows.h>

#define block_width 20
#define x_origin 0
#define y_origin 0

Score::Score() : score(0) {}

void Score::drawOtherBlock(int body_x, int body_y, int width, int height, const char* pic) {
    IMAGE img;
    int len = MultiByteToWideChar(CP_ACP, 0, pic, -1, NULL, 0);
    wchar_t* wPic = new wchar_t[len];
    MultiByteToWideChar(CP_ACP, 0, pic, -1, wPic, len);
    loadimage(&img, wPic, width, height);
    delete[] wPic;
    putimage(body_x, body_y, &img);
}

void Score::eraseOtherBlock(int body_x, int body_y, int width, int height) {
    setcolor(RGB(230, 255, 150));
    setfillcolor(RGB(230, 255, 150));
    fillrectangle(body_x, body_y, body_x + width, body_y + height);
}

void Score::increase() {
    score++;
    display();
}

void Score::display() {
    switch (score) {
    case 0:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "0.png");
        break;
    case 1:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "1.png");
        break;
    case 2:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "2.png");
        break;
    case 3:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "3.png");
        break;
    case 4:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "4.png");
        break;
    case 5:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "5.png");
        break;
    case 6:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "6.png");
        break;
    case 7:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "7.png");
        break;
    case 8:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "8.png");
        break;
    case 9:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "9.png");
        break;
    case 10:
        eraseOtherBlock(400, 0, 50, 50);
        drawOtherBlock(400, 0, 50, 50, "1.png");
        drawOtherBlock(460, 0, 50, 50, "0.png");
        drawOtherBlock(200, 430, 200, 60, "WIN.png");
        break;
    }
}

int Score::getScore() {
    return score;
}